package view {
	import org.puremvc.as3.multicore.utilities.startupmanager.model.StartupMonitorProxy;	
	import org.puremvc.as3.multicore.interfaces.INotification;	
	
	import mx.controls.Text;	
	
	import view.components.ApplicationHeader;	
	
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;	
	
	/**
	 * @author Darshan Sawardekar
	 */
	public class ApplicationHeaderMediator extends Mediator {
		
		static public const NAME:String = "ApplicationHeaderMediator";
		
		public function ApplicationHeaderMediator(viewComponent:ApplicationHeader) {
			super(NAME, viewComponent);
		}		
		
		public function get applicationHeader():ApplicationHeader {
			return viewComponent as ApplicationHeader;
		}
		
		public function get headerText():Text {
			return applicationHeader.headerText as Text;
		}
		
		override public function listNotificationInterests():Array {
			return [StartupMonitorProxy.LOADING_PROGRESS,
					 StartupMonitorProxy.LOADING_COMPLETE,
					 StartupMonitorProxy.LOADING_FINISHED_INCOMPLETE];
		}
		
		override public function onRegister():void {
			
		}
		
		override public function handleNotification(note:INotification):void {
			var name:String = note.getName();
			switch (name) {
			
				case StartupMonitorProxy.LOADING_PROGRESS:
					var percent:Number = note.getBody() as Number;
					setHeaderStatusText(String(percent) + "%");
					break;
					
				case StartupMonitorProxy.LOADING_COMPLETE:
					setHeaderStatusText("READY");
					break;
					
				case StartupMonitorProxy.LOADING_FINISHED_INCOMPLETE:
					setHeaderStatusText("INCOMPLETE");
					break;
					
			}
		}
		
		private function setHeaderText(text:String):void {
			headerText.text = text;
		}
		
		private function setHeaderStatusText(text:String):void {
			setHeaderText("StartupSimpleDemo - MulticoreTest [ " + text + " ]");
		}
		
	}
}
